import HTMLTestRunner
import os
import sys
import unittest
import time

def createsuite():
    disvovers = unittest.defaultTestLoader.discover("../Test",pattern="Test_*.py",top_level_dir=None)
    print(disvovers)
    return disvovers

if __name__ == '__main__':
    # 创建HTML报告生成文件夹，获取当前脚本存放的路径
    curpath = sys.path[0]

    # 创建文件夹
    if not os.path.exists(curpath+'/resultreport'):
        os.makedirs(curpath+'/resultreport')

    # 文件夹命名(以生成文件的时间进行命名）
    now = time.strftime("%Y-%m-%d-%H %M %S",time.localtime(time.time()))

    filename = curpath+'/resultreport/'+now+'resultreport.html'

    with open(filename,'wb') as fp:
        runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title=u"测试报告",description=u"用例执行情况",verbosity=2)
        suite = createsuite() # 调用测试套件
        runner.run(suite)